﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Portalz.Engine
{
    public class Character
    {
        string sName;
        int iHealth, iPower, iLevel, iAttack, iDefense, iExperience;
        int iExperienceNeeded, iKills, iDeaths, iMoney, iTotalHealth;
        int iTotalPower, iAccuracy, iSpeed, iClass, iTarget;
        Item[] inventory = new Item[1];

        public Character(String name, Int32 Class)
        {
            sName = name;
            iClass = Class;
            iHealth = Data.classes[iClass].BaseHealth;
            iPower = Data.classes[iClass].BasePower;
            iLevel = Data.MIN_LEVEL;
            iAccuracy = Formulas.accuracy(this, Data.classes[iClass]);
            iAttack = Formulas.attack(this, Data.classes[iClass]);
            iDefense = Formulas.defense(this, Data.classes[iClass]);
            iMoney = 30;
            iExperience = 0;
            iExperienceNeeded = 50;
            iSpeed = Formulas.speed(this, Data.classes[iClass]);
            iTotalHealth = this.Health;
            iTotalPower = this.Power;
            iKills = iDeaths = 0;
        }

        public Character(string name)
        {
            this.Load(name);
        }

        public void LevelUp()
        {
            iLevel += 1;
            Data.WriteLine("Leveled Up! Now Level " + Level);
        }

        public void Load(string name)
        {
            sName = name;
            iClass = Data.ini.ReadInteger(name, "class", 0);
            iHealth = Data.ini.ReadInteger(name, "health", Data.classes[iClass].BaseHealth);
            iPower = Data.ini.ReadInteger(name, "power", Data.classes[iClass].BasePower);
            iLevel = Data.ini.ReadInteger(name, "level", Data.MIN_LEVEL);
            iAccuracy = Data.ini.ReadInteger(name, "accuracy", Formulas.accuracy(this, Data.classes[iClass]));
            iAttack = Data.ini.ReadInteger(name, "attack", Formulas.attack(this, Data.classes[iClass]));
            iDefense = Data.ini.ReadInteger(name, "defense", Formulas.defense(this, Data.classes[iClass]));
            iMoney = Data.ini.ReadInteger(name, "money", 30); ;
            iExperience = Data.ini.ReadInteger(name, "experience", 0);
            iExperienceNeeded = Data.ini.ReadInteger(name, "experienceNeeded", 50); ;
            iSpeed = Data.ini.ReadInteger(name, "speed", Formulas.speed(this, Data.classes[iClass]));
            iTotalHealth = Data.ini.ReadInteger(name, "totalHealth", this.Health);
            iTotalPower = Data.ini.ReadInteger(name, "totalPower", this.Power);
            iKills = Data.ini.ReadInteger(name, "kills", 0);
            iDeaths = Data.ini.ReadInteger(name, "deaths", 0); 
        }

        public void Save()
        {
            string section = this.Name;
            Data.ini.Write(section, "class", iClass);
            Data.ini.Write(section, "health", iHealth);
            Data.ini.Write(section, "power", iPower);
            Data.ini.Write(section, "level", iLevel);
            Data.ini.Write(section, "accuracy", iAccuracy);
            Data.ini.Write(section, "attack", iAttack);
            Data.ini.Write(section, "defense", iDefense);
            Data.ini.Write(section, "money", iMoney);
            Data.ini.Write(section, "experience", iExperience);
            Data.ini.Write(section, "experienceNeeded", iExperienceNeeded);
            Data.ini.Write(section, "speed", iSpeed);
            Data.ini.Write(section, "totalHealth", iTotalHealth);
            Data.ini.Write(section, "totalPower", iTotalPower);
            Data.ini.Write(section, "kills", iKills);
            Data.ini.Write(section, "deaths", iDeaths);
            Data.loadCharacterList();
        }

        #region Properties
        public string Name
        {
            get { return sName; }
            set { sName = value; }
        }

        public int Health
        {
            get { return iHealth; }
            set { iHealth = value; }
        }

        public int Power
        {
            get { return iPower; }
            set { iPower = value;}
        }

        public int Level
        {
            get { return iLevel; }
            set { iLevel = value; }
        }

        public int Attack
        {
            get { return iAttack; }
            set { iAttack = value; }
        }

        public int Defense
        {
            get { return iDefense; }
            set { iDefense = value; }
        }

        public int Experience
        {
            get { return iExperience; }
            set { iExperience = value; }
        }

        public int ExperienceNeeded
        {
            get { return iExperienceNeeded; }
            set { iExperienceNeeded = value; }
        }

        public int Kills
        {
            get { return iKills; }
            set { iKills = value; }
        }

        public int Deaths
        {
            get { return iDeaths; }
            set { iDeaths = value; }
        }

        public int Money
        {
            get { return iMoney; }
            set { iMoney = value; }
        }

        public int TotalHealth
        {
            get { return iTotalHealth; }
            set { iTotalHealth = value; }
        }

        public int TotalPower
        {
            get { return iTotalPower; }
            set { iTotalPower = value; }
        }

        public int Accuracy
        {
            get { return iAccuracy; }
            set { iAccuracy = value; }
        }

        public int Speed
        {
            get { return iSpeed; }
            set { iSpeed = value; }
        }

        public int Class
        {
            get { return iClass; }
            set { iClass = value; }
        }

        public int Target
        {
            get { return iTarget; }
            set { iTarget = value; }
        }

        public Item[] Inventory
        {
            get { return inventory; }
            set { inventory = value; }
        }
        #endregion
    }
}
